package com.googlecode.garbagecan.dbtest.vertica;

import com.googlecode.garbagecan.dbtest.Callback;

import java.sql.*;

public class TestQueryPerformance {
	
	public static void main(String[] args) throws Exception {

//		doIt(new Callback() {
//			public void execute() throws Exception {
//				Connection conn = getConnection();
//				String sql = "select count(*) from LSF_BJOBS_BAK";
//				for (int i = 0 ; i < 10; i++ ) {
//					PreparedStatement ps = conn.prepareStatement(sql);
//					ResultSet rs = ps.executeQuery();
//					while (rs.next()) {
//						System.out.println(rs.getString(1));
//					}
//					rs.close();
//					ps.close();
//				}
//				conn.close();
//			}
//		});
		
//		doIt(new Callback() {
//			public void execute() throws Exception {
//				Connection conn = getConnection();
//				String sql = "select * from LSF_BJOBS_BAK where random() < 0.5 ORDER BY TIME_STAMP_GMT DESC limit 10000";
//				PreparedStatement ps = conn.prepareStatement(sql);
//				ResultSet rs = ps.executeQuery();
//				int idx = 0;
//				while (rs.next()) {
//					idx++;
//				}
//				System.out.println(idx);
//				rs.close();
//				ps.close();
//				conn.close();
//			}
//		});
		
	}

	private static Connection getConnection() throws Exception {
		Class.forName("com.vertica.Driver");
		String url = "jdbc:vertica://perf2:5433/simulate";
		Connection conn = DriverManager.getConnection(url, "pa8", "simulate");
		conn.setAutoCommit(false);
		return conn;
	}

	private static void doIt(Callback callback) throws Exception {
		long start = System.currentTimeMillis();
		callback.execute();
		long stop = System.currentTimeMillis();
		System.out.println("Time used: " + (stop - start) + " ms");
	}
}
